import request from "./request";
// 登录
export const loginApi = (params) => request.post("/login", params);
// 注册
export const registerApi = (params) => request.post("/register", params);
// /dishlist
export const dishListApi = (params) => request.post("/dishlist", params);
// restaurant
export const restaurantApi = () => request.get("/restaurant");
// cart
export const cartApi = (params) => request.post("/cart", params);
// getCart
export const getOrdersApi = (params) => request.post("/getCart", params);
// deleteFromCart
export const deleteOrderApi = (params) =>
  request.post("/deleteFromCart", params);
// /updateCart
export const updateOrderApi = (params) => request.post("/updateCart", params);
// order
export const orderApi = (params) => request.post("/order", params);
// getOrders
export const getOrdersApi1 = (params) => request.post("/getOrders", params);
// addrestaurant
export const addRestaurantApi = (params) =>
  request.post("/addrestaurant", params);
// /deleterestaurant
export const deleteRestaurantApi = (params) =>
  request.post("/deleterestaurant", params);

// addDish
export const addDishApi = (params) => request.post("/addDish", params);
// deleteDish
export const deleteDishApi = (params) => request.post("/deleteDish", params);
// get("/info")
export const userInfoApi = (params) => request.post("/info", params);
// updateUserInfo
export const updateUserInfoApi = (params) =>
  request.post("/updateUser", params);
// uploadAvatar
export const uploadAvatarApi = (formData) =>
  request.post("/uploadAvatar", formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
// post("/deleteUser"
export const deleteUserApi = (params) => request.post("/deleteUser", params);
// get("/allusers"
export const allUsersApi = () => request.get("/allusers");
// post("/usersdelid"
export const deleteUserByIdApi = (params) =>
  request.post("/usersdelid", params);
// get("/restaurantdetail"
export const restaurantDetailApi = (params) =>
  request.post("/restaurantdetail", params);
// toggleOnSaleApi
export const toggleOnSaleApi = (params) =>
  request.post("/toggleOnSale", params);
// /getDishDetail

export const getDishDetailApi = (params) =>
  request.post("/getDishDetail", params);

// post("/cancelOrder"

export const cancelOrderApi = (params) => request.post("/cancelOrder", params);
// post("/getAllOrders"

export const getAllOrdersApi = (params) =>
  request.post("/getAllOrders", params);
// post("/getHistoryOrders

export const getHistoryOrdersApi = (params) =>
  request.post("/getHistoryOrders", params);
// toggleMerchantStatusApi

export const toggleMerchantStatusApi = (params) =>
  request.post("/restaurantstatus", params);

//post("/recharge"
export const rechargeApi = (params) => request.post("/recharge", params);
// get("/recharge"  user_id

export const getUserRechargeApi = (params) =>
  request.post("/getrecharge", params);
// post("/calculateTotalAmount"

export const calculateTotalAmountApi = (params) =>
  request.post("/calculateTotalAmount", params);
// post("/calculateBalance"

export const calculateBalanceApi = (params) =>
  request.post("/calculateBalance", params);
// post("/getRechargeAmount"

export const getRechargeAmountApi = (params) =>
  request.post("/getRechargeAmount", params);
//post("/addExpenditure"

export const addExpenditureApi = (params) =>
  request.post("/addExpenditure", params);

// 充值申请相关API
export const createRechargeRequestApi = (params) =>
  request.post("/createRechargeRequest", params);
export const getUserRechargeRequestsApi = (params) =>
  request.post("/getUserRechargeRequests", params);
export const getRechargeRequestsApi = (params) =>
  request.post("/getRechargeRequests", params);
export const processRechargeRequestApi = (params) =>
  request.post("/processRechargeRequest", params);

// 优惠券相关API
export const getAvailableCouponsApi = (params) =>
  request.post("/getAvailableCoupons", params);
export const validateCouponApi = (params) =>
  request.post("/validateCoupon", params);
export const calculateCouponsDiscountApi = (params) =>
  request.post("/calculateCouponsDiscount", params);

// router.post("/addComments"
export const addCommentsApi = (params) => request.post("/addComments", params);

// ==================== 营销系统API ====================

// 测试营销路由
export const testMarketingApi = () => {
  return request.get("/marketing/test");
};

// 营销系统相关API（已移除重复的优惠券API，使用上面的订单系统优惠券API）
export const claimCouponApi = (couponId) => {
  return request.post(`/marketing/coupons/${couponId}/claim`);
};

export const createCouponApi = (couponData) => {
  return request.post("/marketing/coupons", couponData);
};

// 积分相关
export const getMyPointsApi = () => {
  return request.get("/marketing/points/my");
};

export const getPointRecordsApi = (limit = 20, offset = 0) => {
  return request.get("/marketing/points/records", { params: { limit, offset } });
};

export const exchangePointsApi = (points, exchangeType, description) => {
  return request.post("/marketing/points/exchange", {
    points,
    exchange_type: exchangeType,
    description
  });
};

export const addPointsApi = (userId, points, description) => {
  return request.post("/marketing/points/add", {
    user_id: userId,
    points,
    description
  });
};

// 签到相关
export const checkinApi = () => {
  return request.post("/marketing/checkin");
};

export const getCheckinStatusApi = () => {
  return request.get("/marketing/checkin/status");
};
